package com.artPreter.service.impl;


import com.artPreter.mapper.IndexTypeMapper;
import com.artPreter.pojo.IndexType;
import com.artPreter.service.IIndexsTypeService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * <p>
 * 艺术分类表 服务实现类
 * </p>
 *
 * @author jarvis
 * @since 2024-12-10
 */
@Service
public class IndexTypeServiceImpl extends ServiceImpl<IndexTypeMapper, IndexType> implements IIndexsTypeService {

    @Override
    public List<IndexType> getList(IndexType indexType) {
        LambdaQueryWrapper<IndexType> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(IndexType::getStatus,1);
        List<IndexType> result= this.baseMapper.selectList(queryWrapper);
        return result;
    }

    @Override
    public void add(IndexType indexType) {
        indexType.setStatus(1);
        // 生成UUID并设置到实体对象中
        String uuid = UUID.randomUUID().toString();
        indexType.setTypeId(uuid);
        this.baseMapper.insert(indexType);
    }

    @Override
    public IPage<IndexType> getPage(Integer currentPage, Integer size, IndexType indexType) {
        IPage<IndexType> indexTypeIPage = new Page<>(currentPage, size);
        LambdaQueryWrapper<IndexType> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(IndexType::getStatus,1);
        indexTypeIPage = this.baseMapper.selectPage(indexTypeIPage, queryWrapper);
        return indexTypeIPage;
    }

    @Override
    public void edit(IndexType indexType) {
        this.baseMapper.updateById(indexType);
    }

    @Override
    public void delete(IndexType indexType) {
        this.baseMapper.deleteById(indexType);
    }
}
